/*
 * 项   目：code-generator
 * 作   者：LuoYiMin
 * 邮   箱：1725990142@qq.com
 * 创建时间：2018/12/27 15:17
 */
package com.roin.util.code.generator.controller;

import com.roin.util.code.generator.model.ControllerConfig;
import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;

import java.net.URL;
import java.util.ResourceBundle;

public class ControllerConfigController extends BaseController {
    private ControllerConfig config;
    /**
     * 是否需要list方法
     */
    @FXML
    private CheckBox listCheckBox;
    @FXML
    private CheckBox listPermissionCheckBox;
    /**
     * 是否需要add方法
     */
    @FXML
    private CheckBox addCheckBox;
    @FXML
    private CheckBox addPermissionCheckBox;
    /**
     * 是否需要update方法
     */
    @FXML
    private CheckBox updateCheckBox;
    @FXML
    private CheckBox updatePermissionCheckBox;
    /**
     * 是否需要delete方法
     */
    @FXML
    private CheckBox deleteCheckBox;
    @FXML
    private CheckBox deletePermissionCheckBox;
    /**
     * 是否需要batchDelete方法
     */
    @FXML
    private CheckBox batchDeleteCheckBox;
    @FXML
    private CheckBox batchDeletePermissionCheckBox;

    @Override
    public void initialize(URL location, ResourceBundle resources) {

    }

    public void setConfig(ControllerConfig config) {
        this.config = config;
        listCheckBox.setSelected(config.isList());
        listPermissionCheckBox.setSelected(config.isListPermission());
        addCheckBox.setSelected(config.isAdd());
        addPermissionCheckBox.setSelected(config.isAddPermission());
        updateCheckBox.setSelected(config.isUpdate());
        updatePermissionCheckBox.setSelected(config.isUpdatePermission());
        deleteCheckBox.setSelected(config.isDelete());
        deletePermissionCheckBox.setSelected(config.isDeletePermission());
        batchDeleteCheckBox.setSelected(config.isBatchDelete());
        batchDeletePermissionCheckBox.setSelected(config.isBatchDeletePermission());
    }

    public ControllerConfig getConfig() {
        return config;
    }

    @FXML
    public void submitConfig(){
        config.setList(listCheckBox.isSelected());
        config.setListPermission(listPermissionCheckBox.isSelected());
        config.setAdd(addCheckBox.isSelected());
        config.setAddPermission(addPermissionCheckBox.isSelected());
        config.setUpdate(updateCheckBox.isSelected());
        config.setUpdatePermission(updatePermissionCheckBox.isSelected());
        config.setDelete(deleteCheckBox.isSelected());
        config.setDeletePermission(deletePermissionCheckBox.isSelected());
        config.setBatchDelete(batchDeleteCheckBox.isSelected());
        config.setBatchDeletePermission(batchDeletePermissionCheckBox.isSelected());
        closeDialogStage();
    }
}
